package com.oauth.service.application.subscription;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;

import com.oauth.service.application.subscription.beans.MemberApplicationRelation;
import com.oauth.service.application.subscription.dao.ApplicationSubscriptionDAO;

public class ApplicationSubscriptionServiceImpl implements ApplicationSubscriptionService {

	private ApplicationSubscriptionDAO mApplicationSubDAO;

	/**
	 * @param pApplicationDAO
	 *            the applicationDAO to set
	 */
	@Autowired(required = true)
	public void setApplicationSubDAO(ApplicationSubscriptionDAO pApplicationSubDAO) {
		mApplicationSubDAO = pApplicationSubDAO;
	}

	public Set<Long> getMemberApplications(Long pMemberId) {
		MemberApplicationRelation memberApplications = mApplicationSubDAO
				.getMemberApplications(pMemberId);
		if (memberApplications == null) {
			return new HashSet<Long>(2);
		}
		return memberApplications.getApplicationIdSet();
	}

	public MemberApplicationRelation addMemberToApplication(Long pMemberId, Long pApplicationId) {

		return mApplicationSubDAO.addMemberToApplication(pMemberId, pApplicationId);
	}

	public MemberApplicationRelation removeMemberToApplication(Long pMemberId, Long pApplicationId) {
		return mApplicationSubDAO.removeMemberToApplication(pMemberId, pApplicationId);
	}

}
